package com.moli.iov.manager.activemq;


import com.moli.iov.cache.RedisUtil;
import com.moli.iov.manager.ManagerConstant;
import com.moli.iov.manager.model.po.AuthoritySysUser;
import com.moli.iov.manager.service.IAuthoritySysUserService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

/**
 * <p>
 * 延时消息处理
 * </p>
 *
 * @Auther: zql
 * @Date: 2018/11/27 10:40
 */
@Component
@Slf4j
public class MessageHandler {

    protected final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private ThreadPoolTaskExecutor taskExecutor;

    @Autowired
    private IAuthoritySysUserService iAuthoritySysUserService;
    @Autowired
    private RedisUtil redisUtil;

    /**
     * 将用户置为停用状态
     *
     * @param expireUser
     */
    public void handle(Object expireUser) {
        taskExecutor.execute(() -> {
            logger.info("执行mq定时队列开始");
            AuthoritySysUser authoritySysUser = (AuthoritySysUser) expireUser;
            iAuthoritySysUserService.updateUser(authoritySysUser);
            redisUtil.delete(ManagerConstant.USER_AUTH_TAG_PREFIX+((AuthoritySysUser) expireUser).getId());
            logger.info("执行mq定时队列结束");
        });
    }
}
